<%@ include file="/common/taglibs.jsp"%>

<head>
    <title><fmt:message key="paymentsCutDetail.title"/></title>
    <meta name="heading" content="<fmt:message key='paymentsCutDetail.heading'/>"/>
    <meta name="menu" content="RoleAdminPayment"/>

    <script type="text/javascript" src="<c:url value='/scripts/calendar/calendar.js'/>"></script>
    <script type="text/javascript" src="<c:url value='/scripts/calendar/lang/calendar-es.js'/>"></script>
    <script type="text/javascript" src="<c:url value='/scripts/calendar/calendar-setup.js'/>"></script>

    <script type="text/javascript">
        window.onload = function() {
            Calendar.setup({
                inputField: "datePay",
                ifFormat: "%d/%m/%Y",
                button: "datePay"
            });
        }

        function retrieveURL(url)
        {
            if (window.XMLHttpRequest)
            {
                // Non-IE browsers
                req = new XMLHttpRequest();
                req.onreadystatechange = processStateChange;
                try {
                    req.open("GET", url, true);
                } catch (e) {
                    alert(e);
                }
                req.send(null);
            } else if (window.ActiveXObject) { // IE
                req = new ActiveXObject("Microsoft.XMLHTTP");
                if (req) {
                    req.onreadystatechange = processStateChange;
                    req.open("GET", url, true);
                    req.send();
                }
            }
        }

        function processStateChange() {
            if (req.readyState == 4) { // Complete
                if (req.status == 200) { // OK response
                    document.getElementById("cutProcessList").innerHTML = req.responseText;
                } else {
                    alert("Problem: " + req.statusText);
                }
            }
        }
    </script>
</head>
<div id="help" >
    <h2>
        <a href="<c:url value='helpPaymentsCutForm.html?decorate=false'/>"
           title="<fmt:message key="help.pCF"/>"
           onclick="Modalbox.show(this.href, {title: this.title, width: 600}); return false;">
            <fmt:message key="help"/>
        </a>
    </h2>
</div>

<table>
    <tr>
        <td>
            <s:form id="paymentsCutForm" action="savePaymentsCut" method="post" validate="true">
                <s:hidden id="paymentsCutId" name="paymentsCut.id" value="%{paymentsCut.id}"/>

                <c:if test="${editable}">
                    <s:textfield id="availableAmount" label="%{getText('availableAmount')}" value="%{availableAmount}" disabled="true" cssClass="text medium"/>
                </c:if>
                <s:textfield id="amount" key="paymentsCut.amount" required="true" cssClass="text medium"/>
                <s:textfield id="datePay" key="paymentsCut.datePay" readonly="true" required="true" cssClass="text medium"/>
                <s:textfield id="code" key="paymentsCut.code" required="true" cssClass="text medium"/>
                <s:textfield id="observation" key="observation" required="true" cssClass="text medium"/>

                <s:hidden id="editable" name="editable" value="%{editable}"/>
                <li class="buttonBar bottom">
                    <c:if test="${editable}">
                        <s:submit cssClass="button" method="save" key="button.save" theme="simple"/>
                    </c:if>
                    <c:if test="${not empty paymentsCut.id && editable}">
                        <s:submit cssClass="button" method="delete" key="button.delete" onclick="return confirmDelete('paymentsCut')" theme="simple"/>
                    </c:if>
                    <s:submit cssClass="button" method="cancel" key="button.cancel" theme="simple"/>
                </li>
            </s:form>
        </td>
        <td align="right" style="vertical-align:top;" width="430">
            <c:if test="${editable}">
                <a id="cutProcessAvailableId" href="javascript:retrieveURL('ajaxCutProcessList.html?decorate=false&editable=true&id='+document.getElementById('paymentsCutId').value);" ><fmt:message key="asignationCutPay.cutProcessAvailable"/></a>
            </c:if>
            <c:if test="${!editable}">
                <a id="cutProcessDetailId" href="javascript:retrieveURL('ajaxCutProcessList.html?decorate=false&id='+document.getElementById('paymentsCutId').value);" ><fmt:message key="asignationCutPay.cutProcessDetail"/></a>
            </c:if>
            <div id="cutProcessList" />
        </td>
    </tr>
</table>

<script type="text/javascript">
    Form.focus($("amount"));
</script>